package com.wenwei.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wenwei.parking.R;


/**
 * Created by Administrator on 2017/5/24.
 *
 * 自定义删除dialog
 */
public class CustomDelDialog extends Dialog{


    private TextView showContentTv;
    private TextView mOkTv;
    private TextView mCancelTv;
    private TextView mSubContentTv;
    private String showMsg ="";
    private String showSubMsg;

    private String onOkMsg;
    private String onCancelMsg;
    public CustomDelDialog(Context context) {
        super(context);
    }

    public void onOkMsg(String leftStr,String rightStr ){
        onCancelMsg = rightStr;
        onOkMsg = leftStr;
    }
    public void setDialogMsg(String s){
        showMsg = s;
    }
    public void setDialogSubMsg(String s){
        showSubMsg = s;
    }
    private DelDialogEvent mCallBack;

    public void setDelDialogEvent(DelDialogEvent event){
        mCallBack = event;
    }

    public interface DelDialogEvent{

        void onDelete();//确定删除

        void onCancel();//取消
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_del_dialog);
        setCanceledOnTouchOutside(false);
        initView();
        initEvent();
    }

    private void initEvent() {
        mOkTv .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCallBack!=null){
                    mCallBack.onDelete();
                }
            }
        });

        mCancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCallBack!=null){
                    mCallBack.onCancel();
                }
            }
        });
    }

    private void initView() {
        mSubContentTv = (TextView) findViewById(R.id.del_dialog_sub_content);
        showContentTv = (TextView) findViewById(R.id.del_dialog_content);
        showContentTv.setText(showMsg);
        mOkTv = (TextView) findViewById(R.id.del_dialog_ok);
        mCancelTv = (TextView) findViewById(R.id.del_dialog_cancel);
        if(showSubMsg != null && !showSubMsg.equals("")){
            mSubContentTv.setText(showSubMsg);
            mSubContentTv.setVisibility(View.VISIBLE);
        }
        if(onCancelMsg !=null && onCancelMsg.equals("")){
            mCancelTv.setText(onCancelMsg);
        }

        if(onOkMsg !=null && onOkMsg.equals("")){
            mOkTv.setText(onOkMsg);
        }
    }
}

